#include "dlg_updateuser.h"
#include "ui_dlg_updateuser.h"

Dlg_UpdateUser::Dlg_UpdateUser(QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::Dlg_UpdateUser)
{
    ui->setupUi(this);
}

Dlg_UpdateUser::~Dlg_UpdateUser()
{
    delete ui;
}

void Dlg_UpdateUser::setType(int id)
{
    m_id=id;
    auto l=Sqlmgr::getinstance()->getUser(QString("where id=%1").arg(id));
    if(1==l.size())
    {
        auto data=l[0];
        ui->le_username->setText(data[1]);
        ui->le_password->setText(data[2]);
        ui->le_auth->setText(data[3]);
        ui->le_grade->setText(data[4]);
        ui->le_department->setText(data[5]);
    }
}

void Dlg_UpdateUser::on_btn_OK_clicked()
{
    QStringList l;
    l<<QString::number(m_id);
    l<<ui->le_username->text();
    l<<ui->le_password->text();
    l<<ui->le_auth->text();
    l<<ui->le_grade->text();
    l<<ui->le_department->text();
    if(-1!=m_id)
    {
        //更改
        Sqlmgr::getinstance()->updateUser(l);
    }
    this->hide();
}


void Dlg_UpdateUser::on_btn_cancel_clicked()
{
    this->hide();
}

